﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using Class_Entity;
using System.Web.Configuration;


namespace DataAccess
{
    public class DAContactUs
    {
        SqlConnection con;
        SqlCommand cmd;


        public bool Add_ContactUs(ContactUs cu)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spAddContactUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@Name", cu.BranchName);
                cmd.Parameters.AddWithValue("@add", cu.Address);
                cmd.Parameters.AddWithValue("@phone", cu.Phone);
                cmd.Parameters.AddWithValue("@fax", cu.Fax);
                


                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //-----------------------------------------------------------------------------------

        public bool Edit_ContactUs(ContactUs cu)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spEditContactUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", cu.ID);
                cmd.Parameters.AddWithValue("@Name", cu.BranchName);
                cmd.Parameters.AddWithValue("@add", cu.Address);
                cmd.Parameters.AddWithValue("@phone", cu.Phone);
                cmd.Parameters.AddWithValue("@fax", cu.Fax);


                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //-------------------------------------------------------------------------------------------

        public bool Delete_ContactUs(ContactUs cu)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spDeleteContactUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", cu.ID);

                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //---------------------------------------------------------------------------------------------

        public DataSet Find_ContactUs(ContactUs cu)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spFindContactUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", cu.ID);

                cmd.ExecuteNonQuery();

                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }

        //------------------------------------------------------------------------------------------------

        public DataSet Load_ContactUs(ContactUs cu)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spLoadContactUs", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.ExecuteNonQuery();

                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }

        //---------------------------------------------------------------------------------------------

        public DataSet Search_ContactUs(ContactUs cu)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spSearchContactUS", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@name", cu.BranchName);

                cmd.ExecuteNonQuery();

                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }


    }
}
